package com.top.art.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.top.art.bo.UserPageQueryBO;
import com.top.art.entity.UserInfo;
import com.top.art.mapper.UserInfoMapper;
import com.top.art.service.IUserInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import static com.top.art.tool.Tool.notNullAndEmpty;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author hjh
 * @since 2020 -10-04
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements IUserInfoService {

    /**
     * Page page.
     *
     * @param bo the bo
     * @return the page
     */
    @Override
    public IPage<UserInfo> page(UserPageQueryBO bo) {
        return page(new Page<>(bo.getCurrent(), bo.getSize()), Wrappers.<UserInfo>lambdaQuery()
                .like(notNullAndEmpty(bo.getName()), UserInfo::getName, bo.getName())
                .in(CollectionUtils.isNotEmpty(bo.getAccountIds()), UserInfo::getAccount, bo.getAccountIds())
                .orderByDesc(UserInfo::getModifyAt, UserInfo::getId));
    }
}
